<template>
	<el-dialog title="选择方案权限适用渠道" :visible.sync="dialogVisible" size="small" :close-on-click-modal="false" :close-on-press-escape="false" :before-close="off">
		  <el-form label-width="150px" >
		  <el-row :span="24">
		  	<el-form-item label="方案权限适用渠道" label-width="150px" :span="24">
				<el-select v-model="agentCodes" multiple  placeholder="方案权限适用渠道" filterable size="small" style="width:80%">
					<el-option v-for="item in agentOptions" :key="item.agentcode" :label="item.agentcode + '-' + item.agentname" :value="item.agentcode"></el-option>
				</el-select>
			</el-form-item>
		  </el-row>
		</el-form>
		  <span slot="footer" class="dialog-footer">
			   <el-button @click="off">取 消</el-button>
			   <el-button type="danger" @click="clear">清 空</el-button>
			   <el-button type="success" @click="select">确 定</el-button>
		  </span>
	</el-dialog>
</template>

<script>

import PlanAPI from "../../../../js/production/plan/planAPI";

  export default {
	data() {
		return {
			dialogVisible: true,
			agentCodes: [],
			agentOptions: [],
		}
	},
	mounted() {
		PlanAPI.queryAgent(this);
		let applychannels = this.$parent.formData.applychannel;
		if(applychannels !== '') {
			this.agentCodes = applychannels.split(',');
		}
	},
	methods: {
		select() {
			this.$parent.formData.applychannel = '';
			this.$parent.arrayAgentCodes = this.agentCodes;
			for(let i = 0; i <this.agentCodes.length - 1; i++) {
				this.$parent.formData.applychannel += this.agentCodes[i] + ",";
			}
			if(this.agentCodes.length > 0) {
				this.$parent.formData.applychannel += this.agentCodes[this.agentCodes.length - 1];
			}
			this.off();
		},
		clear() {
			this.agentCodes = [];
			this.$parent.formData.applychannel = '';
			this.off();
		},
		off() {
			this.$parent.showPlan2AgentDialog = false;
		}
	}
  }
</script>